// license-header java merge-point
package edu.uoc.tfc.gui.parts.carregaClients;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionMapping;

import edu.uoc.tfc.dto.ClientVO;
import edu.uoc.tfc.gui.common.Option;
import edu.uoc.tfc.gui.common.SelectBox;

/**
 * @see edu.uoc.tfc.gui.parts.carregaClients.CarregaClientsController
 */
public class CarregaClientsControllerImpl extends CarregaClientsController
{
    /**
     * @see edu.uoc.tfc.gui.parts.carregaClients.CarregaClientsController#carregaClients(org.apache.struts.action.ActionMapping, edu.uoc.tfc.gui.parts.carregaClients.CarregaClientsForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
     */
    public final void carregaClients(ActionMapping mapping, edu.uoc.tfc.gui.parts.carregaClients.CarregaClientsForm form, HttpServletRequest request, HttpServletResponse response) throws Exception
    {
    	SelectBox selectResultado = new SelectBox();

    	ClientVO[] clients = this.getPartService()
    			.carregaClients();

    	Option[] options = new Option[clients.length];
    	for (int i=0; i<clients.length; i++){
    		Option o = new Option();
    		ClientVO c = clients[i];
    		
    		o.setOptionDisplay(c.getPrimerCognom() + " " + c.getSegonCognom() + ", " + c.getNom() + " - " + c.getDni());
    		o.setOptionValue(c.getId().toString());
    		options[i]=o;
    	}
    	
    	selectResultado.setOptions(options);
    	form.setSelectResultat(selectResultado);    	
    }

}